package command;

import guimessage.Message;

import javax.swing.JTextArea;

import controller.Contact;
import controller.GUIController;

public class SendMessage implements ICommand {

	private JTextArea textarea;
	private GUIController guicontroller;
	private Contact contact;
	
	public SendMessage(JTextArea textarea, Contact c) {
		this.textarea = textarea;
		this.guicontroller = GUIController.getInstance();
		this.contact = c;
	}

	public void execute()
	{
		String text = textarea.getText();
		
		if(text.length() != 0)
		{
			guicontroller.gui.getChatScreen().writeDiscussion("me > " + text + "\n", contact.getIpAddr());
			guicontroller.messages.add( new Message( text , contact) );
			textarea.setText("");
		}
	}
}